package com.zzsy.carosshopprojects.view.dialog;

import android.app.Activity;
import android.view.View;
import android.widget.TextView;

import com.zzsy.carosshopprojects.R;
import com.zzsy.carosshopprojects.adapter.ChoseOilAdapter;
import com.zzsy.carosshopprojects.bean.GetOilsListBean;
import com.zzsy.carosshopprojects.view.MyGridView;

import java.util.List;

/**
 * 优惠券
 */
public class ChoseOilDialog extends BaseDialog {

    private MyGridView recyclerView;
    private TextView tv_cancel, tv_out;
    private List<GetOilsListBean> list;
    private ChoseOilAdapter choseOilAdapter;
    private String goodids;
    private OnClickLister onClickLister;

    public ChoseOilDialog(Activity mActivity, List<GetOilsListBean> list, OnClickLister onClickLister) {
        super(mActivity);
        this.list = list;
        this.onClickLister = onClickLister;
    }

    @Override
    public int getAnimStyle() {
        return R.style.AnimationPrevieww;
    }

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_choseoil;
    }

    @Override
    public void initView(View view) {
        recyclerView = findViewById(R.id.recyclerView);
        tv_cancel = findViewById(R.id.tv_cancel);
        tv_out = findViewById(R.id.tv_out);
//        List<GetOilsListBean> newList = new ArrayList<>();
//        for (int i = 0; i < list.size(); i++) {//只显示显示不下的油品
//            if (i > 5) {
//                newList.add(list.get(i));
//            }
//        }
        choseOilAdapter = new ChoseOilAdapter(getContext(), list, 0, false);
        recyclerView.setAdapter(choseOilAdapter);
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        recyclerView.setOnItemClickListener((adapterView, view1, position, l) -> {
            onClickLister.select(position);
            dismiss();
        });
        tv_out.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
    }

    public interface OnClickLister {
        void select(int p);
    }


}
